<?PHP
    include_once('Configs/database.php');
    include_once('Models/HocPhan.php');
    include_once('Models/HPMoVaoHKNH.php');
    include_once('Models/LopHocPhan.php');
    include_once('Models/ThoiKhoaBieu.php');
    include_once('Models/CanBoGiangDay.php');
    include_once('Models/ChuongTrinhDaoTao.php');
    include_once('Models/DeCuongHPChiTiet.php');
    include_once('Models/Quyen.php');
    include_once('Models/BoMon.php');
    include_once('Models/CanBoDaoTao.php');
    include_once('Models/CanBoGiangDay.php');
    include_once('Models/NguoiQuanTri.php');
    include_once('Models/SinhVien.php');
    //$db = new database();
    if ($_GET['func']=='hienthibmtheokhoa'){
        $bm = new BoMon();
        //$bm->setMaKhoa($_GET['makhoa'])
        $result = $bm->dsBMTheoKhoa($_GET['makhoa']);
                
        echo "<select name='cbobomon' onChange='hienThiLopHPTheoBMHKNH(document.xemnhatkigiangday.cbonamhoc.value,document.xemnhatkigiangday.cbohocki.value,this.value);'>";
        echo "<option value=' '></option>";
        while ($rows = mysql_fetch_array($result))
        {
            echo "<option value='".$rows['mabm']."'>".$rows['tenbm']."</option>";
        }
        
        
        echo "</select>";
    }
    if ($_GET['func']=='taomanhomth'){
            
            $malophp = trim($_GET['malophp']);
            $db = new database();
            $db->setQuery("select substr(max(ltrim(manhomth)),15,2) as nhommax from NhomThucHanh where malophp='".$malophp."'");
            $result = $db->fetchAll();
            $rows = mysql_fetch_array($result);
            
            if ($rows['nhommax']!='') $num = $rows['nhommax']+1;
            else $num = 1;
            if ($num<10) $kihieu = "TH"."0".$num;                
            else $kihieu = "TH"."$num";
            $manhomth = $malophp.$kihieu;
            echo trim($manhomth)."|".trim($kihieu);
            
    }
    if ($_GET['func']=='hienthilophptheobmhknh'){
        $namhoc = $_GET['namhoc'];
        $hocki = $_GET['hocki'];
        $mabm = $_GET['mabm'];
        $db = new database();
        $query = "select malophp,kihieu,d.mahp,tenhp, b.maso, concat(holot, ' ', ten) as hoten ";
        $query .= "from BoMon a, CanBoGiangDay b, CanBo c, LopHocPhan d, HocPhan e ";
        $query .= "where namhoc='".$namhoc."' and hocki=".$hocki." and a.mabm='".$mabm."' and a.mabm = b.mabm and b.maso = c.maso and b.maso = d.maso and d.mahp = e.mahp order by d.mahp asc";
        $db->setQuery($query);
        $result = $db->fetchAll();
        $i = 0;
        $numRecord = mysql_num_rows($result);
        
          echo "<table width='800' border='0'>";
           echo "<tr>";
             echo "<td><div class='panel_cn' style=' border:1 #0099FF;'>";
               echo "<fieldset>";
               echo "<legend>Danh sách các lớp học phần </legend>";
                 echo "<table width='800' class='border_1'  id='tbmain' cellpadding='0' cellspacing='0'>";
                     echo "<tr>";
                       echo "<td align='center' width='28' class='main_3' >STT</td>";
                       echo "<td align='center' class='main_3' width='68'>Lớp HP</td>";
                       echo "<td align='center' class='main_3' width='22'>Kh</td>";
                       echo "<td align='center' class='main_3' width='63'>Mã HP</td>";
                       echo "<td align='center' class='main_3' width='204'>Tên Học Phần</td>";
                       echo "<td align='center' class='main_3' width='60'>MSCB </td>";
                       echo "<td align='center' class='main_3' width='146'>Tên Cán Bộ</td>";
                       echo "<td align='center' class='main_3' width='70'>Xem nhật kí</td>";
                     echo "</tr>";
		 
              if ($numRecord > 0){
                    while ($rows = mysql_fetch_array($result)){
                        $i++;
                        $c = 2-$i%2;
                   
               
                     echo "<tr>";
                       echo "<td align='center' class='level_1_$c' >".$i."</td>";
                       echo "<td align='center' class='level_1_$c'>".$rows['malophp']."</td>";
                       echo "<td align='center'  class='level_1_$c'>".$rows['kihieu']."</td>";
                       echo "<td align='center'  class='level_1_$c'>".$rows['mahp']."</td>";
                       echo "<td align='center' class='level_1_$c'>".$rows['tenhp']."</td>";
                       echo "<td align='center' class='level_1_$c'>".$rows['maso']."</td>";
                       echo "<td align='center'  class='level_1_$c'>".$rows['hoten']."</td>";
                       echo "<td align='center'  class='level_1_$c'><input type='radio' name='rdomalophp' value='".$rows['malophp']."'  onClick='printTL(this.value);'  /></td>";
                       
                     echo "</tr>";
					 
                    }
					
                
                }
                else{
                     echo "<tr>";
                       echo "<td align='center' class='level_1_$c' colspan='8'>Không có lớp học phần nào.</td>";
                      
                     echo "</tr>";
                }
               echo "</table>";
               echo "</fieldset>";
             echo "</div></td>";
           echo "</tr>";
         echo "</table> ";
        
    }
    if ($_GET['func']=='hienThiHPTheoHKNH'){
        
        $hphknh = new HPMoVaoHKNH();
        $hphknh->setHocKi($hocki);
        $hphknh->setNamHoc($namhoc);
        $result = $hphknh->dsHocPhanMoVaoHKNH();
        
        echo "<select name='cbohp' onchange='hienThiDSLopHPCuaHPTrongHKNK(document.xepthoikhoabieu.cbonamhoc.value,document.xepthoikhoabieu.cbohocki.value,this.value);'>";
        echo "<option value=' '></option>";
        while ($rows = mysql_fetch_array($result)){
            echo "<option value='".$rows['mahp']."'>".$rows['tenhp']."</option>";
        }
        
        
        echo "</select>";
      
    }
    if ($_GET['func']=='hienThiDSLopHPCuaHPTrongHKNK'){
        $lophp = new LopHocPhan();
        $lophp->setHocKi($hocki);
        $lophp->setNamHoc($namhoc);
        $lophp->setMaHP($mahp);
        $result = $lophp->dsLopHPMoTrongHKNHCuaHP();
        
        echo "<select name='cbolophp' onchange='hienThiSiSoLopHP(this.value);'>";
        echo "<option value=' '></option>";
        while ($rows = mysql_fetch_array($result)){
            echo "<option value='".$rows['malophp']."'>".$rows['kihieu']."</option>";
        }
        
        
        echo "</select>";
    }
    if ($_GET['func']=='hienThiSiSoLopHP'){
        $lophp = new LopHocPhan();
        $lophp->setMaLopHP($_GET['malophp']);
        
        $result = $lophp->thongTinLopHP();
        $rows = mysql_fetch_array($result);
        echo $rows['siso'];
                
        
    }
    
    /*if ($_GET['func']=='hienthidsbm'){
        $bm = new BoMon();
        //$bm->setMaKhoa($_GET['makhoa'])
        $result = $bm->dsTatCaBM();
                
        echo "<select name='cbobomon'>";
        echo "<option value=' '></option>";
        while ($rows = mysql_fetch_array($result))
        {
            echo "<option value='".$rows['mabm']."'>".$rows['tenbm']."</option>";
        }
        
        
        echo "</select>";
    }*/
    if (isset($_GET['form'])){
        //echo "helll";
            if ($_GET['form']=='capnhatlophp'){
                    $namhoc = $_GET['namhoc'];
                    $hocki = $_GET['hocki'];
                    
                    if ($_GET['func']=='hienthihp'){
                        //echo $namhoc.'-'.$hocki;
                        $hphknh = new HPMoVaoHKNH();
                        $hphknh->setHocKi($hocki);
                        $hphknh->setNamHoc($namhoc);
                        $result = $hphknh->dsHocPhanMoVaoHKNH();
                        
                        echo "<select name='cbohp' onchange='taoMaLopHP_KH(document.capnhatlophp.cbonamhoc.value,document.capnhatlophp.cbohocki.value,this.value);'>";
                        echo "<option value=' '></option>";
                        while ($rows = mysql_fetch_array($result)){
                            echo "<option value='".$rows['mahp']."'>".$rows['tenhp']."</option>";
                        }
                        
                        
                        echo "</select>";
                        //echo "<script language='javascript'> document.capnhatlophp.txtmalophp.value = ' '";
                        //echo "document.capnhatlophp.txtkihieu.value = ' '";
                        //echo "document.capnhatlophp.txttuanhoc.value = ' '";
                        //echo "document.capnhatlophp.txtsiso.value = ' '";
                       // echo "taoMaLopHP_KH(document.capnhatlophp.cbonamhoc.value,document.capnhatlophp.cbohocki.value,document.capnhatlophp.cbohp.value)";
                        //echo "</ script>";
                    }
                   if ($_GET['func']=='taomalophp_kh'){
                        //echo "Hello";
                        $mahp = $_GET['mahp'];
                        $db = new database();
                        $db->setQuery("select max(kihieu) as sonhom from LopHocPhan where  mahp='".$mahp."' and hocki=".$hocki." and namhoc='".$namhoc."' group by mahp");
                        $result = $db->fetchAll();
                        $rows = mysql_fetch_array($result);
                        if ($rows['sonhom']!=' ') $num = $rows['sonhom']+1;
                        else $num = 1;
                        if ($num<10) $kihieu = "0".$num;                
                        else $kihieu = "$num";
                        //if ($namhoc != " " && $hocki != 0 && $mahp != " "){
                        $lophp = new LopHocPhan();
                        $lophp->setNamHoc($namhoc);
                        $lophp->setHocKi($hocki);
                        $lophp->setMaHP($mahp);
                        
                        
                        /*$query = "select max(kihieu) as stt from LopHocPhan where namhoc='".$lophp->getNamHoc()."' and hocki=".$lophp->getHocKi()." and a.mahp='".$lophp->getMaHP()."'";
                        echo $query;
                        $result = mysql_query($query);
                        $rows = mysql_fetch_array($result);
                        $stt = $rows['stt'] + 1;
                        if ($stt<10) $kihieu = "0".$stt;                
                        else $kihieu = "$stt";*/
                        $malophp = $mahp.substr($namhoc,2,2).substr($namhoc,7,2).$hocki.$kihieu;
                        //echo $malophp.'-'.$kihieu;
                        
                        if ($lophp->getMaHP() != " " && $lophp->getNamHoc()!= " " && $lophp->getHocKi() != 0){
                            echo trim($malophp).'|'.$kihieu;
                            //echo $malophp.'|'.$kihieu.'|';
                            
                            
                            
                            
                            /*echo "<table align='center' class='font' width='700' border='0' cellspacing='0' cellpadding='0'>";
                              echo "<tr>";
                                echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
                                echo "<td align='center' class='main_1'>Danh sách lớp học phần </td>";
                                echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
                              echo "</tr>";
                            
                                echo "<tr >";
                                	echo "<td class='border_1' colspan='3' valign='top'>";                                                                     
                                     $lophp = new LopHocPhan();
                                     $lophp->setMaLopHP($malophp);
                                     $lophp->setNamHoc($namhoc);
                                     $lophp->setHocKi($hocki);
                                     $lophp->setMaHP($mahp);
                                     $result = $lophp->dsLopHPMoTrongHKNHCuaHP();
                                        $i = 0;
                                        while ($rows = mysql_fetch_array($result))
                                        {
                                               $i++;  
                                                                                                  
                                            echo "<table width='700' class='border_1' style='border:none' id='tbmain' cellpadding='0' cellspacing='0'>";
                                           
                                                echo "<tr>";
                                                    //echo "<td align='left' class='main_3'> Lớp HP: <div id='malophp$i' width='100'>".$rows['malophp']."</div>--Kí hiệu:<div id='kihieu$i'>".$rows['kihieu']."</div>--Sĩ số: <div id='siso$i'>".$rows['siso']."</div>--Tuần học:<div id='tuanhoc$i'>".$rows['tuanhoc']."</div></td>";
                                                    echo "<td align='left'  bgcolor='#DAE9F3' style='font-weight:bold' width='60'>Lớp HP: </td>";
                                                    echo "<td align='left' bgcolor='#DAE9F3'><div id='malophp$i'>".$rows['malophp']."</div></td>";
                                                    echo "<td align='left' bgcolor='#DAE9F3' style='font-weight:bold' width='50'>Kí hiệu: </td>";
                                                    echo "<td align='left' bgcolor='#DAE9F3'><div id='kihieu$i'>".$rows['kihieu']."</div></td>";
                                                    echo "<td align='left' bgcolor='#DAE9F3' style='font-weight:bold' width='50'>MSCB: </td>";
                                                    echo "<td align='left' bgcolor='#DAE9F3'><div id='maso$i'>".$rows['maso']."</div></td>";
                                                    echo "<td align='left'  bgcolor='#DAE9F3' style='font-weight:bold' width='40'>Sĩ số: </td>";
                                                    echo "<td align='left' bgcolor='#DAE9F3'><div id='siso$i'>".$rows['siso']."</div></td>";
                                                    echo "<td align='left' bgcolor='#DAE9F3' style='font-weight:bold' width='70'>Tuần học:</td>";
                                                    echo "<td align='left' bgcolor='#DAE9F3'><div id='tuanhoc$i'>".$rows['tuanhoc']."</div></td>";
                                                    echo "<td align='center' width='100'  bgcolor='#DAE9F3' style='font-weight:bold'>Chọn";
                                                    echo "<input type='radio' name='chkchon' value=$i onClick='getValue(this.value);' >";
                                                        //echo "<input type='submit' name='btnsualophp' value='Sửa' class='button_1'/>";
                                                       //echo " <input type='submit' name='btnxoalophp' value='Xóa'  class='button_1'/>";
                                                        //echo "<input name='btncapnhattkb' type='submit'  class='button_1' id='btncapnhattkb' value='Cập nhật TKB'/>";
                                                    echo "</td>";
                                                   
                                                echo "</tr>";
                                                echo "<tr bgcolor='#FFFFFF'>";
                                                    echo "<td align='center' colspan='11'><table width='400' border='0' class='border_1'>";
                                                      echo "<tr>";
                                                        echo "<td colspan='4' align='center' style='font-size: 18'><b>Thời Khóa Biểu</b> </td>";
                                                      echo "</tr>";
                                                      $tkb = new ThoiKhoaBieu();
                                                      $tkb->setMaLopHP($rows['malophp']);
                                                      $resulttkb = $tkb->thoiKhoaBieuLopHP();
                                                      $numtkb = mysql_num_rows($resulttkb);
                                                      if ($numtkb > 0){
                                                      echo "<tr>";
                                                        echo "<td width='30' align='center'><b>Thứ</b></td>";
                                                        echo "<td width='60' align='center'><b>Tiết BĐ</b></td>";
                                                        echo "<td width='60' align='center'><b>Số Tiết</b></td>";
                                                        echo "<td width='60' align='center'><b>Phòng</b></td>";
                                                        
                                                      echo "</tr>";
                                                     
                                                      while ($rowstkb = mysql_fetch_array($resulttkb)){
                                                      echo "<tr>";
                                                        echo "<td align='center'>".$rowstkb['thu']."</td>";
                                                        echo "<td width='60' align='center'>".$rowstkb['tietbd']."</td>";
                                                        echo "<td width='60' align='center'>".$rowstkb['sotiet']."</td>";
                                                        echo "<td width='60' align='center'>".$rowstkb['maphong']."</td>";
                                                        
                                                      echo "</tr>";
                                                      }
                                                      }
                                                      else{
                                                      echo "<tr>";
                                                        echo "<td width='30' align='center' colspan='4'><b>Chưa sắp Thời khóa biểu</b></td>";
                                                        
                                                        
                                                      echo "</tr>";
                                                      }
                                                      echo "<tr>";
                                                        echo "<td align='center'  colspan='4'>";
                                                            //echo "<a href='Views/Capnhatthoikhoabieu.php?malophp=".$rows['malophp']."&kihieu=".$rows['kihieu']."' target='_blank'>Cập nhật TKB</a>";
                                                            echo "<a href='index.php?option=capnhattkb&malophp=".$rows['malophp']."&siso=".$rows['siso']."'>";
                                                            //echo "<a href='Views/Capnhatthoikhoabieu.php?malophp=".$rows['malophp']."&kihieu=".$rows['kihieu']." ' target='_blank'>";
                                                            echo "<input type='button' name='btncapnhattkb'  value='Cập nhật TKB' class='button_1'>";
                                                            echo "</a>";
                                                        echo "</td>";
                                                       
                                                        
                                                      echo "</tr>";
                                                    echo "</table> ";                   
                                                    echo "</td>";
                                                    
                                                echo "</tr>";
                                                
                                                
                                            echo "</table>";
                                            
                                        }
                                        
                                    echo "</td>";
                             echo " </tr>";
                             echo "<tr>";
                                $num = $num - 1;
                                echo "<td  align='left' class='main_3' colspan='9'  style='color:#FF0000'>Tổng số lớp học phần:". $num;
                                echo "</td>";
                             echo "</tr>"; 
                            echo "</table>";
                            */        
                         }
                         else{
                            $malophp = " ";
                            $kihieu = " ";
                            $table = " ";
                            echo $malophp.'|'.$kihieu.'|'.$table;
                        }
                    }
                    if ($_GET['func']=='hienthitencb'){
                        $cb = new CanBoGiangDay();
                        $maso = trim($_GET['maso']);
                        $cb->setMaSo($maso);
                        $rows = mysql_fetch_array($cb->thongtinCanBo());
                        echo "<input type=text name='txttencb' value='". $rows['hoten']."'/>";
                        
                        
                    }
                 
                
            }
            if ($_GET['form']=='capnhattkb'){
                    if ($_GET['func']=='xepphong'){
                        //$malophp = $_GET['malophp'];
                        $hocki = $_GET['hocki'];
                        $namhoc = $_GET['namhoc'];
                        $siso = $_GET['siso'];
                        $thu = $_GET['thu'];
                        $tietbd = $_GET['tietbd'];
                        $sotiet = $_GET['sotiet'];
                        $tkb = new ThoiKhoaBieu();
                        
                        //$query = "select maphong from Phong where succhua>=".$siso." and maphong not in "; 	           
                        //$query .= "(select a.maphong from ThoiKhoaBieu a, Phong b ";			
                        //$query .= "where a.maphong = b.maphong and  (thu=".$thu."  and ";
                        //$query .= "(((".$tietbd."+".$sotiet."-1)>=tietbd and (tietbd+sotiet-1)>=(".$tietbd."+".$sotiet."-1))or (".$tietbd.">=tietbd and (tietbd+sotiet-1)>=".$tietbd.") or ((tietbd+sotiet-1)=".$tietbd.") or (tietbd=(".$tietbd."+".$sotiet."-1)))))";
                        $query = "select maphong from Phong where succhua>=".$siso." and maphong not in "; 	           
                        $query .= "(select a.maphong from ThoiKhoaBieu a, Phong b, LopHocPhan c ";			
                        $query .= "where a.maphong = b.maphong and a.malophp=c.malophp and hocki='".$hocki."' and namhoc='".$namhoc."' and  (thu=".$thu."  and ";
                        $query .= "(((".$tietbd."+".$sotiet."-1)>=tietbd and (tietbd+sotiet-1)>=(".$tietbd."+".$sotiet."-1))or (".$tietbd.">=tietbd and (tietbd+sotiet-1)>=".$tietbd.") or ((tietbd+sotiet-1)=".$tietbd.") or (tietbd=(".$tietbd."+".$sotiet."-1)))))";
                        $db = new database();
                        $db->setQuery($query);
                        //echo $db->getQuery();
                        
                        
                        
                        $result = $db->fetchAll();
                        echo "<select name='cbomaphong'>";
                        echo "<option value=' '></option>";
                        while ($rows = mysql_fetch_array($result)){
                            echo "<option value='".$rows['maphong']."'>".$rows['maphong']."";
                            echo "</option>";
                        }
                        echo "</select>";
                        
                       
                    }
                    
             }
             
             // form Xem nhat ki 
              if ($_GET['form']=='xemnhatki'){
                    $namhoc = $_GET['namhoc'];
                    $hocki = $_GET['hocki'];
                    $mahp = $_GET['mahp'];
                    if ($_GET['func']=='hienthihp'){
                        //echo $namhoc.'-'.$hocki;
                        $hphknh = new HPMoVaoHKNH();
                        $hphknh->setHocKi($hocki);
                        $hphknh->setNamHoc($namhoc);
                        $result = $hphknh->dsHocPhanMoVaoHKNH();
                        
                        echo "<select name='cbohp' onchange='showLopHPXemNhatKi(document.xemnhatki.cbonamhoc.value,document.xemnhatki.cbohocki.value,this.value);'>";
                        echo "<option value=' '></option>";
                        while ($rows = mysql_fetch_array($result)){
                            echo "<option value='".$rows['mahp']."'>".$rows['tenhp']."</option>";
                        }
                        
                        
                        echo "</select>";
                      
                    }
                    if ($_GET['func']=='hienthilophp'){
                        $lophp = new LopHocPhan();
                        $lophp->setHocKi($hocki);
                        $lophp->setNamHoc($namhoc);
                        $lophp->setMaHP($mahp);
                        $result = $lophp->dsLopHPMoTrongHKNHCuaHP();
                        
                        echo "<select name='cbolophp'>";
                        echo "<option value=' '></option>";
                        while ($rows = mysql_fetch_array($result)){
                            echo "<option value='".$rows['malophp']."'>".$rows['kihieu']."</option>";
                        }
                        
                        
                        echo "</select>";
                    }
            }
            //het form xem nhat ki
            
            //form cap nhat hoc phan
            
            if ($_GET['form']=='capnhathp')
            {
               
                $mahp = $_GET['mahp'];
                $hp = new HocPhan();
                $hp->setMaHP($mahp);
                if ($_GET['func']=='hienthithongtinHP')
                {
                    $result = $hp->thongtinHP();
                    
                    $rows = mysql_fetch_array($result);
                    $tailieuthamkhao = str_replace("\\","",$rows['tailieuthamkhao']);
                    $tailieuthamkhao = stripslashes($tailieuthamkhao);
                    $thongtingv = stripslashes($rows['thongtingv']);
                    $ppgiangday = stripslashes($rows['ppgiangday']);
                    $muctieu = stripslashes($rows['muctieu']);
                    $danhgiahp = stripslashes($rows['danhgiahp']);
                    //echo $rows['tenhp']
                    echo $rows['tenhp'].'|'.$rows['sotc'].'|'.$rows['sotietlithuyet'].'|'.$rows['sotietthuchanh'].'|'.$rows['hptienquyet'].'|';
                    echo $rows['manhom'].'|'.$thongtingv.'|'.$rows['tenfile'].'|'.$muctieu.'|'.$ppgiangday.'|'.$danhgiahp.'|'.$tailieuthamkhao;
                  
                }
                
          } 
            
          //het form cap nhat hoc phan
          
          //form cap nhat chuong trinh dao dao
          if ($_GET['form']=='capnhatctdt')
          {
         
            $manganh = $_GET['manganh'];
            $ctdt = new ChuongTrinhDaoTao();
            $ctdt->setMaNganh($manganh);
            if ($_GET['func']=='hienthidshptheochuyennganh')
            {
                 
                 $result = $ctdt->dsHPTheoCTDT();
                 $num = mysql_num_rows($result);
                 if ($num > 0){
                    echo "<table align='center' class='font' width='800' border='0' cellspacing='0' cellpadding='0'>";
                      echo "<tr>";
                        echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
                        echo "<td align='center' class='main_1'>Danh sách học phần của chuyên ngành</td>";
                        echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
                      echo "</tr>";
                      echo "<tr >";
                        echo "<td class='border_1' colspan='3' valign='top'><table width='800' class='border_1' style='border:none' id='tbmain' cellpadding='0' cellspacing='0'>";
                          echo "<tr>";
                            echo "<td align='center' class='main_3' width='30'>STT</td>";
                            echo "<td align='center' class='main_3' width='50'>Mã HP</td>";
                            echo "<td align='center' class='main_3' width='400'>Tên Học Phần</td>";
                            echo "<td align='center' class='main_3' width='70'>Số Tín Chỉ</td>";
                            echo "<td align='center' class='main_3' width='100'>Số tiết BB </td> ";       
                            echo "<td align='center' class='main_3' width='100'>Số tiết TC </td>";
                            echo "<td align='center' class='main_3' width='50'>Chọn</td>";
                          echo "</tr>";
                          
                      
                    	
                    		
                    		$i=0;
                    		$ci=0;
                    		//echo "<tbody style='display:none;'>";
                    		while($rows=mysql_fetch_array($result))
                    		{
                    			$i++;
                    			$ci=2-$i%2;
                    			//if($i==$bg) echo "</tbody>";
                    			echo "<tr>";
                    			echo "<td align='center' class='main_3'>".$i."</td>";
                    			echo "<td class='level_1_$ci' align='center'><div id='mahp$i'>".$rows['mahp']."</div></td>";
                    			echo "<td class='level_1_$ci' align='left'><div id='tenhp$i'>&nbsp;&nbsp;".$rows['tenhp']."</div></td>";
                    		
                    			echo "<td class='level_1_$ci' align='center'><div id='sotc$i'>".$rows['sotc']."</div></td>";			
                    			echo "<td class='level_1_$ci' align='center'><div id='sotietbb$i'>".$rows['sotietbatbuoc']."</div></td>";
                    			echo "<td class='level_1_$ci' align='center'><div id='sotiettc$i'>".$rows['sotiettuchon']."</div></td>";
                    			echo "<td class='level_1_$ci' align='center'><input type='radio' name='rdochon' value=$i onClick='getValue(this.value);' ></td>";
                    			
                    		
                    			echo "</tr>";
                    		
                    			 //echo "<tbody style='display:none;'>";
                    		}
                    		//echo "</tbody>";
                    	
                    
                         echo "<tr>";
                            echo "<td align='left' colspan='3'><span style=' color:#008000'>Số học phần:".$num;
                              
                            echo "</span></td>";
                            echo "<td align='right' colspan='10'><font color='green'></font></td>";
                          echo "</tr>";
                        echo "</table></td>";
                      echo "</tr>";
                    echo "</table>";
                }
                else{
                    echo "<table align='center' class='font' width='800' border='0' cellspacing='0' cellpadding='0'>";
                      echo "<tr>";
                        echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
                        echo "<td align='center' class='main_1'>Danh sách học phần của chuyên ngành</td>";
                        echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
                      echo "</tr>";
                      echo "<tr >";
                            echo "<td class='border_1' colspan='3' valign='top' align='center'>";
                            echo "Chưa có học phần nào</td>";    
                            echo "</td>";
                        echo "</tr >";
                    echo "</table>";
                }    
                    //echo $rows['tenhp'].'|'.$rows['sotc'].'|'.$rows['sotietlithuyet'].'|'.$rows['sotietthuchanh'];
              
            }
            
          }   
          //het form cap nhat chuong trinh dao dao 
          
          
          //Form xem de cuong
          if ($_GET['form']=='xemdecuong')
          {
                $manganh = $_GET['manganh'];
                $ctdt = new ChuongTrinhDaoTao();
                $ctdt->setMaNganh($manganh);
            
            if ($_GET['func']=='hienThiHPTheoNganh')
            {
                //echo $namhoc.'-'.$hocki;
                
                $result = $ctdt->dsHPTheoCTDT();
                
                echo "<select name='cbohp'>";
                echo "<option value=' '>Chọn học phần</option>";
                while ($rows = mysql_fetch_array($result))
                {
                    echo "<option value='".$rows['mahp']."'>".$rows['tenhp']."</option>";
                }
                
                
                echo "</select>";
               
            }
          }
          //het form xem de cuong
          
          
          //form cap nhat de cuong chi tiet
            if ($_GET['form']=='capnhatdcct')
            {
                $mahp = $_GET['mahp'];
                /*$dcct= new DeCuongHPChiTiet();
                $dcct->setMaHP($mahp);*/
                $hp = new HocPhan();
                $hp->setMaHP(trim($mahp));
            
                if ($_GET['func']=='hienThiDCCTCuaHP'){
                    
                
                
                    //$result = $dcct->dsDeCuongChiTietCuaHP();
                    $result = $hp->dsDeCuongHPChiTiet();
                    $num = mysql_num_rows($result);
                    
            
                    //tao ma de cuong
                    //$hp->setQuery("select max(madc) as max from DeCuongHPChiTiet where mahp = '".$hp->getMaHP()."'");
                    //$resultmadc = $hp->fetchAll();
                    //$nummadc = mysql_num_rows($resultmadc);
                    
                    //$rowsmadc = mysql_fetch_array($resultmadc);
                    //$stt = substr(trim($rowsmadc['max']),4,2);
                    //if ($stt > 0) $num = $stt + 1;
                    //else $stt = 1;
                    //if ($stt < 10) $madc = $mahp."A".$stt;                
                    //else $madc = $mahp."$stt";
                    //$madc = $mahp.$madc;
                    
                    if ($num > 0)
                    {
                        $hp->setQuery("select max(madc) as max from DeCuongHPChiTiet where mahp = '".$hp->getMaHP()."'");
                        $resultmadc = $hp->fetchAll();
                        $rowsmadc = mysql_fetch_array($resultmadc);
                        $stt = substr(trim($rowsmadc['max']),5,2);
                        $stt = $stt + 1;
                        if ($stt < 10) $madc = $mahp."0".$stt;                
                        else $madc = $mahp."$stt";
                        echo $madc.'|';
                        echo "<table align='center' class='font' width='800' border='0' cellspacing='0' cellpadding='0'>";
                          echo "<tr>";
                            echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
                            echo "<td align='center' class='main_1'>Danh sách Đề cương học phần chi tiết </td>";
                            echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
                          echo "</tr>";
                          echo "<tr >";
                                echo "<td class='border_1' colspan='3' valign='top'>";
                                    echo "<table width='800' border='0' align='center' cellpadding='0' cellspacing='0'>";
                                        echo "<tr>";
                                            echo "<td width='60' class='main_3' align='center'><strong>Mã ĐC </strong></td>";
                                            echo "<td align='center' width='200' class='main_3' align='center'><strong>Nội dung tắt</strong></td>";
                                            echo "<td align='center' width='400' class='main_3' align='center'><strong>N&#7897;i dung: </strong></td>";
                                            echo "<td width='70' class='main_3' align='center'><strong>S&#7889; ti&#7871;t </strong></td>";
                                            echo "<td width='70' class='main_3' align='center'><strong>Ghi chú </strong></td>";
                                            echo "<td width='70' class='main_3' align='center'><strong>Chọn</strong></td>";
                                        echo "</tr>";
                                                
                                        $i=0;
                                                    
                                        while ($record = mysql_fetch_array($result))
                                        {    
                                            $i++;
                                             $ci = 2-$i%2;       
                                        echo "<tr>";
                                            echo "<td  class='level_1_$ci'><div id='madc$i'>".$record['madc']."</div></td>";
                                            echo "<td  class='level_1_$ci'><div id='noidungvt$i'>".$record['noidungvt']."</div></td>";
                                            echo "<td  class='level_1_$ci'><div id='noidung$i'>".$record['noidung']."</div></td>";
                                            echo "<td  class='level_1_$ci' align='center'><div id='sotiet$i'>".$record['sotiet']."</div></td>";
                                            echo "<td  class='level_1_$ci' align='center'>&nbsp;<div id='ghichu$i'>".$record['ghichu']."</div></td>";
                                            echo "<td  class='level_1_$ci' align='center'><input type='radio' name='chkchon' value=$i onClick='getValue(this.value);' ></td>";       
                                        echo "</tr>";
                 
                                    }
                                               
                                    echo "</table>";
                                echo "</td>";
                            echo "</tr >";
                        echo "</table>";
                    }
                    else
                    {
                        
                        include_once('Models/HocPhan.php');
                        $hp = new HocPhan();
                        if ($hp->isExits("HocPhan","mahp='".$mahp."'")>0){
                            echo $mahp."0".'1'.'|';
                            echo "<table align='center' class='font' width='800' border='0' cellspacing='0' cellpadding='0'>";
                              echo "<tr>";
                                echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
                                echo "<td align='center' class='main_1'>Đề cương học phần chi tiết </td>";
                                echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
                              echo "</tr>";
                              echo "<tr >";
                                    echo "<td class='border_1' colspan='3' valign='top'>";
                                    echo "<tc> Chưa có đề cương chi tiết</td>";    
                                    echo "</td>";
                                echo "</tr >";
                            echo "</table>";
                        }
                        else
                        {
                            echo ' '.'|';
                            echo "<table width='800' border='0' align='center' cellpadding='20'>";
                                echo "<tr>";
                                    echo "<td  class='main_3' align='center'><strong>Không tồn tại học phần này </strong></td>";
                                    
                                echo "</tr>";
                                        
                                            
                                
                            echo "</table>";
                        }
                        
                    }
                
                }
                
               
               
            } 
            //het form cap nhat de cuong chi tiet   
            
            if ($_GET['form']=='phanquyen')
            {
                $maquyen= $_GET['maquyen']; 
                $quyen = new Quyen();
                $quyen->setMaQuyen($maquyen);
            	$result = $quyen->dsChucNangQuenThucHien();
                echo "<table align='center' class='font' width='500' border='0' cellspacing='0' cellpadding='0'>";
                  echo "<tr>";
                    echo "<td class='main_1'><img border='0' src='Libraries/images/tbl_left.gif' width='10' height='25' /></td>";
                    echo "<td align='center' class='main_1'>Danh sách Khoa</td>";
                    echo "<td class='main_1'><p align='right'><img border='0' src='Libraries/images/tbl_right.gif' width='10' height='25' /></p></td>";
                  echo "</tr>";
                  echo "<tr >";
                    echo "<td class='border_1' colspan='3' valign='top'><table width='500' class='border_1' style='border:none' id='tbmain' cellpadding='0' cellspacing='0'>";
                      echo "<tr>";
                        echo "<td width='30' align='center' class='main_3'>STT</td>";
                        echo "<td width='50' align='center' class='main_3'>Mã CN</td>";
                        echo "<td width='300' align='center' class='main_3'>Tên Chức năng </td>";
                        
                		echo "<td width='50' align='center' class='main_3'>Chọn</td>";
                        
                        echo "</tr>";
                     
                  
                	
                	 	
                		
                		
                		$bg=($curPg-1)*10+1;
                		$end=$bg+9;	
                		$num=mysql_num_rows($result);
                		$i=0;
                		$ci=0;
                		
                		while($row=mysql_fetch_array($result))
                		{
          		            /*$cn = new ChucNang();
                            $parent = $row['parent'];
                            $resultcn = $cn->thongTinCN($parent);
                            $rowcn = mysql_fetch_array($resultcn);
                            if ($row['parent']==''){
                                $tenncn = $row['tencn'];
                            }
                            else $tenncn = $rowcn['tencn'];*/
                			$i++;
                			$ci=2-$i%2;
                			
                			echo "<tr>";
                			echo "<td align='center' class='main_3'>".$i."</td>";
                            echo "<td class='level_1_$ci' align='center'><div id='macn$i'>".$row['macn']."</div></td>";
                			echo "<td class='level_1_$ci' align='left'><div id='tencn$i'>".$row['tencn']."</div></td>";
                			
                			
                		
                			echo "<td class='level_1_$ci' align='center'><input type='radio' name='chkchon' value='$i' onClick='getValue(this.value);' ></td>";
                		
                			echo "</tr>";
                		
                			
                		}
                		
                	
                
                
                      
                    echo "</table></td>";
                  echo "</tr>";
                echo "</table>";
            }
            if ($_GET['form']=='capnhatcanbo')
            {
                $loaicb = trim($_GET['loaicb']);
                $maso = trim($_GET['maso']);
                if ($_GET['func'] == 'taomacb'){
                    $db = new database();
                    $db->setQuery("select max(maso) as masomax from CanBo");
                    $result = $db->fetchAll();
                    $rows = mysql_fetch_array($result);
                    //echo $rows['masomax'];
                    if ($rows['masomax']!=' ') $maso = $rows['masomax'] + 1;
                    else $maso = 1;
                    //echo (7-strlen($maso));
                    $len = 7-strlen($maso);
                    for ($i=0; $i<$len; $i++){
                        $maso = "0".$maso;
                    }
                    echo $maso;
                }
                 if ($_GET['func'] == 'hienthittcb'){
                    if ($loaicb == 'GV'){
                        $gv = new CanBoGiangDay();
                        $gv->setMaSo($maso);
                        $query = "select a.maso,  holot, ten, date_format(ngaysinh, '%d-%m-%Y') as ngaysinh, phai, diachi, email, sodt,hocvi,chucdanh,maquyen, d.mabm as mabm from CanBoGiangDay a, CanBo b,NguoiDung c, Bomon d";
                        $query .= " where  a.maso='".$gv->getMaSo()."' and a.maso = b.maso and b.maso=c.maso and a.mabm = d.mabm";
                        $gv->setQuery($query);    
                        $result = $gv->fetchAll();
                        $rows = mysql_fetch_array($result);
                       
                        
                        echo trim($rows['holot'])."|".trim($rows['ten'])."|".$rows['ngaysinh']."|".$rows['phai']."|";
                        echo $rows['diachi']."|".$rows['email']."|".$rows['sodt']."|".$rows['hocvi']."|"." "."|".$rows['mabm']."|".$rows['chucdanh']."|".$rows['maquyen'];
                       
                    }
                    if ($loaicb == 'AD'){
                        $ad = new NguoiQuanTri();
                        $ad->setMaSo($maso); 
                        $query = "select a.maso,  holot,ten, date_format(ngaysinh, '%d-%m-%Y') as ngaysinh,phai, diachi, email, sodt,hocvi,nghiepvu from NguoiQuanTri a, CanBo b";
                        $query .= " where  a.maso='".$ad->getMaSo()."' and a.maso = b.maso";
                        $ad->setQuery($query);
                          
                        $result = $ad->fetchAll();
                        $rows = mysql_fetch_array($result);
                        
                        echo trim($rows['holot'])."|".trim($rows['ten'])."|".$rows['ngaysinh']."|".$rows['phai']."|";
                        echo $rows['diachi']."|".$rows['email']."|".$rows['sodt']."|".$rows['hocvi']."|".$rows['nghiepvu'];
                    }
                    if ($loaicb == 'DT'){
                        $dt = new CanBoDaoTao();
                        $dt->setMaSo($maso);
                         $query = "select a.maso, holot,ten, date_format(ngaysinh, '%d-%m-%Y') as ngaysinh, phai, diachi, email, sodt,hocvi,nghiepvu from CanBoDaoTao a, CanBo b";
                        $query .= " where  a.maso='".$dt->getMaSo()."' and a.maso = b.maso";
                        $dt->setQuery($query);
                        
                        $result = $dt->fetchAll(); 
                        $rows = mysql_fetch_array($result);
                        
                        echo $rows['holot']."|".$rows['ten']."|".$rows['ngaysinh']."|".$rows['phai']."|";
                        echo $rows['diachi']."|".$rows['email']."|".$rows['sodt']."|".$rows['hocvi']."|".$rows['nghiepvu'];
                    }
                 }
                
            }
            if ($_GET['form']=='capnhatsinhvien')
            {
                
                $maso = trim($_GET['maso']);
               
                 if ($_GET['func'] == 'hienthittsv'){
                   
                        
                        
                        $sv = new SinhVien();
                        $sv->setMaSo($maso);    
                        $result = $sv->thongTinSinhVien();
                        $rows = mysql_fetch_array($result);
                       
                        
                        echo trim($rows['hoten'])."|".$rows['ngaysinh']."|".$rows['phai']."|";
                        echo $rows['email']."|".$rows['sodt'];
                       
                    
                    
                 }
                
            }
           
    }
    
?>
